<cfcomponent displayname="CrafterFactory" accessors="yes" output="no">
	
	
	<!--- Properties --->
	<cfproperty name="productCode" type="string" />
	<cfproperty name="springInstance" type="any" />
	<cfproperty name="rootPath" type="string" />
	<cfproperty name="fallBackFilterName" type="string" />
	<cfproperty name="metaDataAccessor" type="any" />
	<cfproperty name="structureAccessor" type="any" />
	<cfproperty name="templatesPath" type="string" />
	<cfproperty name="debugOutput" type="boolean" />
	<cfproperty name="util" type="any" />
	
	
	<!--- init() --->
	<cffunction name="init" access="public" returntype="crafter.CrafterFactory" output="no">
		<cfargument name="productCode" type="string" required="no" />
		<cfargument name="springInstance" type="any" required="no" />
		<cfargument name="rootPath" type="string" required="no" default="" />
		<cfargument name="fallBackFilterName" type="string" required="no" default="FallbackFilter" />
		<cfargument name="templatesPath" type="string" required="no" default="" />
		<cfargument name="debugOutput" type="boolean" required="no" default="false" />
		
		<cftimer label="CrafterFactory.init()" type="debug">
			<cfscript>
				setProductCode(arguments.productCode);
				setSpringInstance(arguments.springInstance);
				setRootPath(arguments.rootPath);
				setFallBackFilterName(arguments.fallBackFilterName);
				setMetaDataAccessor(getSpringInstance().getBean("MetaDataAccessor"));
				setStructureAccessor(getSpringInstance().getBean("StructureAccessor"));
				setTemplatesPath(ExpandPath(arguments.templatesPath));
				setDebugOutput(arguments.debugOutput);
				setUtil(CreateObject("crafter.CrafterUtil"));
				return this;
			</cfscript>
		</cftimer>
	</cffunction>
	
	
	<!--- getDocument() --->
	<cffunction name="getDocument" access="public" returntype="crafter.CrafterDocument" output="no">
		<cfargument name="path" type="string" required="true" />
		<cftimer label="CrafterFactory.getDocument(path = '#arguments.path#')" type="debug">
			<cfset local.oDocument = CreateObject("component","crafter.CrafterDocument").init(
				productCode = getProductCode(),
				crafterFactory = this
			)/>
			<cfset local.oDocument.load(path = arguments.path) />
			<cfreturn local.oDocument />
		</cftimer>
	</cffunction>
	
	
	<!--- getGenericDocument() --->
	<cffunction name="getGenericDocument" access="public" returntype="crafter.CrafterGenericDocument" output="no">
		<cfargument name="path" type="string" required="true" />
		<cftimer label="CrafterFactory.getGenericDocument(path = '#arguments.path#')" type="debug">
			<cfset local.oDocument = CreateObject("component","crafter.CrafterGenericDocument").init(
				productCode = getProductCode(),
				crafterFactory = this
			)/>
			<cfset local.oDocument.load(path = arguments.path) />
			<cfreturn local.oDocument />
		</cftimer>
	</cffunction>
	
	
	<!--- getNewCollection() --->
	<cffunction name="getNewCollection" access="public" returntype="crafter.CrafterCollection" output="no">
		<cfargument name="name" type="string" required="no" default="" />
		<cftimer label="CrafterFactory.getNewCollection(name = '#arguments.name#')" type="debug">
			<cfscript>
				return CreateObject("component","crafter.CrafterCollection").init(name = arguments.name);
			</cfscript>
		</cftimer>
	</cffunction>
	
	
	<!--- getNewDocumentCollection() --->
	<cffunction name="getNewDocumentCollection" access="public" returntype="crafter.CrafterDocumentCollection" output="no">
		<cfargument name="name" type="string" required="no" default="" />
		<cfscript>
			return CreateObject("component","crafter.CrafterDocumentCollection").init(
				name = arguments.name,
				crafterFactory = this
			);
		</cfscript>
	</cffunction>
	
	
	<!--- getNewPathCollection() --->
	<cffunction name="getNewPathCollection" access="public" returntype="crafter.CrafterDocumentCollection" output="no">
		<cfargument name="name" type="string" required="no" default="" />
		<cfscript>
			return CreateObject("component","crafter.CrafterPathCollection").init(
				name = arguments.name,
				crafterFactory = this
			);
		</cfscript>
	</cffunction>
	
	
	<!--- getTextObject() --->
	<cffunction name="getNewTextObject" access="public" returntype="crafter.CrafterText" output="no">
		<cfargument name="text" type="string" required="no" default="" />
		<cfscript>
			return CreateObject("component","crafter.CrafterText").init(
				text = arguments.text
			);
		</cfscript>
	</cffunction>
	
	
	<!--- getPathCollection() --->
	<cffunction name="getPathCollection" access="public" returntype="crafter.CrafterPathCollection" output="no" hint="Created a CrafterCollection by traversing a given folder path.">
		<cfargument name="path" type="string" required="true" />
		<cfargument name="name" type="string" required="false" default="" />
		<cfargument name="depth" type="numeric" required="false" default="1" />
		<cfargument name="filterName" type="string" required="false" default="" />
		<cfargument name="sort" type="string" required="false" default="" />
		<cfscript>
			local.oPathCollection = CreateObject("component","crafter.CrafterPathCollection").init(
				collectionName = arguments.name,
				crafterFactory = this
			);
			
			local.oPathCollection.load(
				path = arguments.path,
				depth = arguments.depth,
				filterName = arguments.filterName
			);
			
			if (arguments.sort NEQ "") {
				local.oPathCollection.sort(direction = arguments.sort);
			}
			
			return local.oPathCollection;
		</cfscript>
	</cffunction>
	
	
	<!--- getContentListCollection() --->
	<cffunction name="getContentListCollection" access="public" returntype="any" output="no">
		<cfargument name="path" type="string" required="no" default="" />
		<cfargument name="doc" type="crafter.CrafterDocument" required="no" />
		<cfargument name="sort" type="string" required="no" default="" />
		<cfscript>
			local.oCollection = CreateObject("component","crafter.CrafterListCollection").init(
				crafterFactory = this
			);
			
			if (arguments.path NEQ "") {
				local.oCollection.load(path = arguments.path);
			}
			else if (IsInstanceOf(arguments.doc,"crafter.CrafterDocument")) {
				local.oCollection.load(doc = arguments.doc);	
			}
			
			if (arguments.sort NEQ "") {
				local.oCollection.sort(direction = arguments.sort);	
			}
			
			return local.oCollection;
		</cfscript>
	</cffunction>
	
	
	<!--- getGroupedContentListCollection() --->
	<cffunction name="getGroupedContentListCollection" access="public" returntype="any" output="no">
		<cfargument name="path" type="string" required="no" default="" />
		<cfargument name="doc" type="crafter.CrafterDocument" required="no" />
		<cfscript>
			local.oGroupedListCollection = CreateObject("crafter.CrafterGroupedListCollection").init(
				crafterFactory = this
			);
			
			if (arguments.path NEQ "") {
				local.oGroupedListCollection.load(path = arguments.path);
			}
			else if (IsInstanceOf(arguments.doc,"crafter.CrafterDocument")) {
				local.oGroupedListCollection.load(doc = arguments.doc);	
			}
			return local.oGroupedListCollection;
		</cfscript>
	</cffunction>
	
	
	<!--- getKeyMap() --->
	<cffunction name="getKeyMap" access="public" returntype="any" output="no">
		<cfargument name="path" type="string" required="true" />
		<cftimer label="crafterFactory.getKeyMap(path = '#arguments.path#')" type="debug">
			<cfscript>
				local.oDocument = CreateObject("component","crafter.CrafterKeyMap").init(
					productCode = getProductCode(),
					crafterFactory = this
				);
				local.oDocument.load(path = arguments.path);
				return local.oDocument;
			</cfscript>
		</cftimer>
	</cffunction>
	
	
	<!--- getDateSeriesDocument() --->
	<cffunction name="getDateSeriesDocument" access="public" returntype="crafter.CrafterDocument" output="no">
		<cfargument name="path" type="string" required="true" />
		<cftimer label="CrafterFactory.getDocument('#arguments.path#')" type="debug">
			<cfset local.oDocument = CreateObject("component","crafter.CrafterDateSeries").init(
				productCode = getProductCode(),
				crafterFactory = this
			)/>
			<cfset local.oDocument.load(path = arguments.path) />
			<cfreturn local.oDocument />
		</cftimer>
	</cffunction>
	
	
	<!--- getMetaObject() --->
	<cffunction name="getMetaObject" access="public" returntype="crafter.CrafterDocumentMeta" output="no">
		<cfargument name="mode" type="string" required="no" default="page-override" />
		<cfscript>
			local.oMetaObject = CreateObject("component","crafter.CrafterDocumentMeta").init(
				productCode = getProductCode(),
				mode = arguments.mode
			);
			return local.oMetaObject;
		</cfscript>
	</cffunction>

	
	<!--- getFilter() --->
	<cffunction name="getFilter" access="public" returntype="any" output="no">
		<cfargument name="name" type="string" required="true" />
		<cfscript>
			try {
				local.oFilter = getSpringInstance().getBean("#arguments.name#");
			}
			catch(Any e) {
				local.oFilter = getSpringInstance().getBean("#getFallBackFilterName()#");
			}
			return local.oFilter;
		</cfscript>
	</cffunction>

	<!--- getFileFromFilePath() --->
	<cffunction name="getFileFromFilePath" access="public" returntype="string" output="no" hint="Given a file path, it returns the filename, intelligently including filenames with dots in them.">
		<cfargument name="showExt" type="boolean" required="false" default="true" />
		<cfargument name="filePath" type="string" required="true" default="" />
		<cfscript>
			local.sFileFromPath = ListLast(arguments.filePath,"/");
			if (arguments.showExt) {
				return local.sFileFromPath;	
			}
			else {
				local.nNumberOfDotsInFileName = ListLen(local.sFileFromPath,".");
				local.sModifiedFileName = "";
				for (local.i = 1; local.i LT local.nNumberOfDotsInFileName; local.i++) {
					local.sModifiedFileName = local.sModifiedFileName & ListGetAt(local.sFileFromPath,i,".");
				}
				return local.sModifiedFileName;
			}
		
		</cfscript>
	</cffunction>
	
	
	<!--- null() --->
    <cffunction name="null" access="public" returntype="any" hint="Utilty method to create null values for ColdFusion" output="no">
        <cfreturn JavaCast("null",0) />
    </cffunction>
	
	
</cfcomponent>